package pers.baiban.sqltoword.handler.impl;

import pers.baiban.sqltoword.handler.AbstractHeaderProcessor;
import pers.baiban.sqltoword.handler.HeaderProcessor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import pers.baiban.sqltoword.util.TableUtil;

import java.util.List;

import static pers.baiban.sqltoword.util.TableUtil.Functors.*;

/**
 * 表头颜色处理器
 *
 * @author 强子初
 * @since 2023/11/29
 */
@Component
@Order(5)
public class HeaderColorProcessor extends AbstractHeaderProcessor implements HeaderProcessor {

    @Override
    public void doHandler() {
        if (needUpdate(param.getHeaderColor())) {
            getCTShd().forEach(shd -> {
                shd.setVal(STShd.CLEAR);
                shd.setFill(param.getHeaderColor());
            });
        }
    }

    /**
     * 获取底纹
     */
    private List<CTShd> getCTShd() {
        return TableUtil.to(cells, CTTC.andThen(TCPR).andThen(SHD));
    }
}